package cn.itcast.controller;

import cn.itcast.constant.MessageConstant;
import cn.itcast.constant.RedisMessageConstant;
import cn.itcast.pojo.Result;
import cn.itcast.utils.JuHeUtils;
import cn.itcast.utils.ValidateCodeUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
@RestController
@RequestMapping("/validateCode")
public class ValidateCodeController {
    @Autowired
    private JedisPool jedisPool;
    @RequestMapping("/send4Order")
    public Result send4Order(@RequestParam("telephone") String telephone){
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        /*try {
            JuHeUtils.getRequest2("13271075035",code.toString());
        } catch (Exception e) {
            return  new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);
        }*/
        System.out.println("发送的手机验证码:"+code);
         jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_ORDER,15*60,code.toString());

return new Result(true,MessageConstant.SEND_VALIDATECODE_SUCCESS);

    }

    @RequestMapping("/send4Login")
    public Result send4Login(@RequestParam("telephone") String telephone){
        Integer code = ValidateCodeUtils.generateValidateCode(4);
        /*try {
            JuHeUtils.getRequest2("13271075035",code.toString());
        } catch (Exception e) {
            return  new Result(false, MessageConstant.SEND_VALIDATECODE_FAIL);
        }*/
        System.out.println("发送的手机验证码:"+code);
        jedisPool.getResource().setex(telephone+ RedisMessageConstant.SENDTYPE_LOGIN,15*60,code.toString());

        return new Result(true,MessageConstant.SEND_VALIDATECODE_SUCCESS);

    }

}
